Skip to content

🧹 Remove unwrap() on required arguments in calendar helper#548

Closed
jpoehnelt wants to merge 1 commit intomainfrom
fix-calendar-unwrap-11601507632249061943
Closed

🧹 Remove unwrap() on required arguments in calendar helper#548
jpoehnelt wants to merge 1 commit intomainfrom
fix-calendar-unwrap-11601507632249061943

Conversation

@jpoehnelt
Copy link
Member

I replaced several .unwrap() calls in src/helpers/calendar.rs with proper error handling to improve code health and prevent potential panics. The affected arguments are calendar, summary, start, and end, which are now handled using .ok_or_else(|| GwsError::Validation(...))?. I also added a changeset file to document the improvement.


PR created automatically by Jules for task 11601507632249061943 started by @jpoehnelt

Replaced `.unwrap()` calls for `calendar`, `summary`, `start`, and `end`
arguments with proper error handling using `.ok_or_else()`. This
prevents potential panics if the `clap` configuration were to change and
instead returns a structured `GwsError::Validation` error.

Added a changeset file for `@googleworkspace/cli` as a patch-level
update.

Co-authored-by: jpoehnelt <3392975+jpoehnelt@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 18, 2026
@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: bbaaecd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the calendar helper by implementing proper error handling for critical, required arguments. It replaces potentially panic-inducing unwrap() calls with explicit error propagation, ensuring that missing arguments are gracefully handled as validation errors rather than causing application crashes.

Highlights

  • Error Handling Improvement: Replaced unwrap() calls with ok_or_else for calendar, summary, start, and end arguments in src/helpers/calendar.rs to prevent panics and improve robustness.
  • Changelog Entry: Added a new changeset file to document this error handling improvement.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@googleworkspace-bot googleworkspace-bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 18, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to improve error handling by removing .unwrap() calls. However, the arguments being handled (calendar, summary, start, end) are already guaranteed to be present by the clap configuration, either through required(true) or default_value(...). This means the original .unwrap() calls were safe and would never panic. The new error handling code is therefore unreachable and should be removed to avoid confusion and keep the code concise.

Comment on lines +427 to +438
let calendar_id = matches
.get_one::<String>("calendar")
.ok_or_else(|| GwsError::Validation("Missing required argument: calendar".to_string()))?;
let summary = matches
.get_one::<String>("summary")
.ok_or_else(|| GwsError::Validation("Missing required argument: summary".to_string()))?;
let start = matches
.get_one::<String>("start")
.ok_or_else(|| GwsError::Validation("Missing required argument: start".to_string()))?;
let end = matches
.get_one::<String>("end")
.ok_or_else(|| GwsError::Validation("Missing required argument: end".to_string()))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While replacing .unwrap() is generally good practice, in this specific case, the unwrap() calls were safe and would not panic. The clap argument parser is configured to ensure these values are always present:

  • summary, start, and end are marked as required(true).
  • calendar has a default_value("primary").

Because of this, matches.get_one() will always return Some(...) for these arguments, and clap would have already exited with an error if a required argument was missing. The added .ok_or_else(...) introduces error handling logic that is unreachable, which can be misleading for future readers. It's better to rely on the unwrap() here, which acts as a correct assertion that the value is present.

Suggested change
let calendar_id = matches
.get_one::<String>("calendar")
.ok_or_else(|| GwsError::Validation("Missing required argument: calendar".to_string()))?;
let summary = matches
.get_one::<String>("summary")
.ok_or_else(|| GwsError::Validation("Missing required argument: summary".to_string()))?;
let start = matches
.get_one::<String>("start")
.ok_or_else(|| GwsError::Validation("Missing required argument: start".to_string()))?;
let end = matches
.get_one::<String>("end")
.ok_or_else(|| GwsError::Validation("Missing required argument: end".to_string()))?;
let calendar_id = matches.get_one::<String>("calendar").unwrap();
let summary = matches.get_one::<String>("summary").unwrap();
let start = matches.get_one::<String>("start").unwrap();
let end = matches.get_one::<String>("end").unwrap();
References
  1. Avoid introducing changes that are outside the primary goal of a pull request to prevent scope creep. In this case, replacing safe unwrap() calls with unreachable error handling adds complexity without addressing a real issue, thus deviating from a truly beneficial improvement.

@github-actions github-actions bot added the gemini: reviewed Gemini Code Assist has reviewed the latest changes label Mar 18, 2026
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.07%. Comparing base (6f92e5b) to head (bbaaecd).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #548      +/-   ##
==========================================
+ Coverage   68.10%   69.07%   +0.97%     
==========================================
  Files          40       42       +2     
  Lines       17954    19269    +1315     
==========================================
+ Hits        12227    13310    +1083     
- Misses       5727     5959     +232     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpoehnelt jpoehnelt closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities cla: yes This human has signed the Contributor License Agreement. gemini: reviewed Gemini Code Assist has reviewed the latest changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants